<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>农产品评价 - 助农购物网站</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="${pageContext.request.contextPath}/logo/favicon.ico">
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .review-card {
            margin-bottom: 20px;
            border: 1px solid #dee2e6;
            border-radius: 5px;
        }
        .rating {
            color: #ffc107;
            font-size: 20px;
        }
        .review-images {
            margin-top: 10px;
        }
        .review-images img {
            width: 100px;
            height: 100px;
            object-fit: cover;
            margin-right: 10px;
            margin-bottom: 10px;
            border-radius: 5px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <jsp:include page="../common/header.jsp"/>
    
    <div class="container mt-4">
        <h2 class="mb-4">我的评价</h2>
        
        <c:if test="${param.message != null}">
            <div class="alert alert-success">${param.message}</div>
        </c:if>
        
        <c:if test="${param.error != null}">
            <div class="alert alert-danger">${param.error}</div>
        </c:if>
        
        <c:if test="${error != null}">
            <div class="alert alert-danger">${error}</div>
        </c:if>
        
        <c:if test="${reviews != null && !empty reviews}">
            <c:forEach var="review" items="${reviews}">
                <div class="card review-card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-2">
                                <c:if test="${review.product != null && review.product.imageUrl != null && !empty review.product.imageUrl}">
                                    <img src="${review.product.imageUrl}" class="img-fluid" alt="${review.product.productName}" 
                                         style="max-width: 120px; max-height: 120px; object-fit: cover; border-radius: 5px; cursor: pointer;"
                                         onclick="location.href='${pageContext.request.contextPath}/client/product?action=detail&id=${review.productId}'">
                                </c:if>
                                <c:if test="${review.product == null || review.product.imageUrl == null || empty review.product.imageUrl}">
                                    <div class="bg-light d-flex align-items-center justify-content-center" 
                                         style="width: 120px; height: 120px; border-radius: 5px;">
                                        <span class="text-muted">暂无图片</span>
                                    </div>
                                </c:if>
                            </div>
                            <div class="col-md-8">
                                <h5 class="card-title">
                                    <c:if test="${review.product != null && review.product.productName != null}">
                                        <a href="${pageContext.request.contextPath}/client/product?action=detail&id=${review.productId}">
                                            ${review.product.productName}
                                        </a>
                                    </c:if>
                                    <c:if test="${review.product == null || review.product.productName == null}">
                                        <a href="${pageContext.request.contextPath}/client/product?action=detail&id=${review.productId}">
                                            商品ID: ${review.productId}
                                        </a>
                                    </c:if>
                                </h5>
                                <div class="mb-2">
                                    <span class="rating">
                                        <c:forEach begin="1" end="${review.rating}">★</c:forEach>
                                        <c:forEach begin="${review.rating+1}" end="5">☆</c:forEach>
                                    </span>
                                    <span class="text-muted ms-2">
                                        <fmt:formatDate value="${review.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                    </span>
                                </div>
                                <p class="card-text">${review.content}</p>
                                
                                <c:if test="${review.images != null && !empty review.images}">
                                    <div class="review-images">
                                        <c:forTokens items="${review.images}" delims="," var="image">
                                            <img src="${image}" alt="评价图片" onclick="window.open('${image}', '_blank')">
                                        </c:forTokens>
                                    </div>
                                </c:if>
                            </div>
                            <div class="col-md-2 text-end">
                                <a href="${pageContext.request.contextPath}/client/review?action=delete&reviewId=${review.reviewId}" 
                                   class="btn btn-sm btn-outline-danger"
                                   onclick="return confirm('确定要删除这条评价吗？删除后无法恢复。')">删除</a>
                            </div>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </c:if>
        
        <c:if test="${reviews == null || empty reviews}">
            <div class="alert alert-info">
                <h5>暂无评价</h5>
                <p>您还没有发表过任何评价。</p>
                <p><a href="${pageContext.request.contextPath}/client/order?action=list">去订单页面评价商品</a></p>
            </div>
        </c:if>
        
        <!-- 分页 -->
        <nav aria-label="Page navigation" class="mt-4">
            <div class="row">
                <div class="col-md-12 text-center mb-3">
                    <span class="text-muted">共 <strong>${totalCount}</strong> 条评论，共 <strong>${totalPages}</strong> 页</span>
                </div>
            </div>
            <ul class="pagination justify-content-center">
                <li class="page-item ${page == 1 ? 'disabled' : ''}">
                    <c:choose>
                        <c:when test="${page == 1}">
                            <span class="page-link">上一页</span>
                        </c:when>
                        <c:otherwise>
                            <a class="page-link" href="?page=${page-1}">上一页</a>
                        </c:otherwise>
                    </c:choose>
                </li>
                <li class="page-item">
                    <span class="page-link">第 ${page} 页 / 共 ${totalPages} 页</span>
                </li>
                <li class="page-item ${hasNextPage == false ? 'disabled' : ''}">
                    <c:choose>
                        <c:when test="${hasNextPage == false}">
                            <span class="page-link">下一页</span>
                        </c:when>
                        <c:otherwise>
                            <a class="page-link" href="?page=${page+1}">下一页</a>
                        </c:otherwise>
                    </c:choose>
                </li>
            </ul>
        </nav>
    </div>
    
    <script src="${pageContext.request.contextPath}/js/bootstrap.bundle.min.js"></script>
</body>
</html>





